package cn.com.connext.scrm.repository.master;

import cn.com.connext.scrm.domain.master.DwaUserInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DWAUserInfoRepository extends JpaRepository<DwaUserInfo, String>, JpaSpecificationExecutor<DwaUserInfo> {
    DwaUserInfo findById(String id);

    @Query(value = "select distinct d.unionId from DwaUserInfo d")
    List<String> findAllUnionId();

    List<DwaUserInfo> findByMobileOrderByLessonLevelDesc(String mobile);

    List<DwaUserInfo> findByUnionIdOrderByLessonLevelDesc(String unionId);

    DwaUserInfo findFirstByMobileAndLessonLevel(String mobile, String lessonLevel);
    @Query(value = "select d.className from DwaUserInfo d group by d.className")
    List<String> findAllClassName();
    @Query(value = "select d.className from DwaUserInfo d where d.mobile = :mobile group by d.className")
    List<String> findClassNameByMobile(@Param("mobile") String mobile);
    @Query(value = "select d.className from DwaUserInfo d where d.lessonCity = :lessonCity group by d.className order by d.lessonLevel desc")
    List<String> findClassNameByLessonCity(@Param("lessonCity") String lessonCity);
    List<DwaUserInfo> findByClassName(String className);
    @Query(value = "select d.lessonCity from DwaUserInfo d where d.mobile = :mobile group by d.lessonCity")
    List<String> findLessonCityByMobile(@Param("mobile") String mobile);
    List<DwaUserInfo> findByLessonCityAndMobileNot(String lessonCity, String mobile);
    List<DwaUserInfo> findByClassNameNotInAndMobileNot(List<String> className, String mobile);
}
